import { PureStandardProps } from "@/src/consts"
import Global from "@/src/lib/global"
import { Image } from "@tarojs/components"
import Section from "./section"
import Taro from "@tarojs/taro"
import { connect } from "react-redux"
import { State } from "@/src/dva/state"
import { UserState } from "@/src/dva/models/user"
import { useContext } from "react"
import { PageWarpperContext } from "@/src/components/page-warpper"
import UserCenterModel from "@/src/lib/models/user_center_model"
// import PageWarpper, { PageWarpperContext } from '@/src/components/page-warpper';


interface OrderSectionProps extends PureStandardProps {
    user: UserState,
    centerModel?: UserCenterModel
}

const OrderSection = (props: OrderSectionProps) => {

    const { centerModel } = props
    let ctx  = useContext(PageWarpperContext);
    
    let onAllBtnClick = () => {
        
        console.log(ctx)
        if(!props.user.isLogin){
            ctx.loginCompentRef?.current?.show()
            return false
        }
        Taro.navigateTo({url: Global.makeNavigateUrl("/pages/subpackages/pages/order/index")})
    }

    return (
        <Section { ...props } 
            title="我的订单"
            indicator={
                <Image onClick={ onAllBtnClick } src={ Global.loadImage("btn_order_all@3x.png") } style={{ width: "125rpx", height: "26rpx" }} />
            }
            items={
                [
                    { icon: "icon_order_paying@3x.png", title: "待付款", url: `/pages/subpackages/pages/order/index?params=${JSON.stringify({ tabIndex: 1 })}`, badge: centerModel?.nopay_num ?? ""},
                    { icon: "icon_order_sending@3x.png", title: "待发货", url: `/pages/subpackages/pages/order/index?params=${JSON.stringify({ tabIndex: 2 })}`, badge: centerModel?.nodeliver_num ?? ""},
                    { icon: "icon_order_receiving@3x.png", title: "待收货", url: `/pages/subpackages/pages/order/index?params=${JSON.stringify({ tabIndex: 3 })}`, badge: centerModel?.noreceive_num ?? ""},
                    { icon: "icon_order_servicing@3x.png", title: "退款/售后", url: "/pages/subpackages/pages/aftermarket-service/index", badge: centerModel?.backmoney_num ?? ""},
                ]
            }/>
    )
}

export default connect((state:State)=>{
    return{
        user:state.user
    }
})(OrderSection) 
